package de.roon.weighttracker;

import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.PreferenceFragment;

public class SettingsFragment extends PreferenceFragment implements OnSharedPreferenceChangeListener {
	public static final String KEY_NAME = "pref_name";
	
	private EditTextPreference txtPref;
	private SharedPreferences sp;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Load the preferences from an XML resource
        addPreferencesFromResource(R.xml.preferences);
        

        // Get shared Preference and write value to Preference
        sp = getPreferenceScreen().getSharedPreferences();
        txtPref = (EditTextPreference) findPreference(getString(R.string.pref_name));
        
        String sName = sp.getString(getString(R.string.pref_name), getString(R.string.pref_name_summary));
        txtPref.setSummary(sName);
   }

	@Override
	public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
		txtPref = (EditTextPreference) findPreference(getString(R.string.pref_name));
        
        String sName = sp.getString(getString(R.string.pref_name), getString(R.string.pref_name_summary));
        txtPref.setSummary(sName);		
	}
}
